from toee import *

def san_dialog( attachee, triggerer ):
	if (attachee.leader_get() != OBJ_HANDLE_NULL):
		triggerer.begin_dialog( attachee, 200 )
	elif (not attachee.has_met(triggerer)):
		if (anyone( triggerer.group_list(), "has_follower", 8040 )):
			triggerer.begin_dialog( attachee, 1 )
		else:
			triggerer.begin_dialog( attachee, 120 )
	elif (anyone( triggerer.group_list(), "has_follower", 8040 )):
		triggerer.begin_dialog( attachee, 170 )
	else:
		triggerer.begin_dialog( attachee, 190 )
	return SKIP_DEFAULT

def san_enter_combat( attachee, triggerer ):
	attachee.float_line(12023,triggerer)
	return RUN_DEFAULT

def san_dying( attachee, triggerer ):
	attachee.float_line(12014,triggerer)
	if (attachee.leader_get() != OBJ_HANDLE_NULL):
		game.global_vars[29] = game.global_vars[29] + 1
	return RUN_DEFAULT

def san_start_combat( attachee, triggerer ):
	while(attachee.item_find(8903) != OBJ_HANDLE_NULL):
		attachee.item_find(8903).destroy()
	if (attachee.d20_query(Q_Is_BreakFree_Possible)):
		create_item_in_inventory( 8903, attachee )
	leader = attachee.leader_get()
	if (leader != OBJ_HANDLE_NULL):
		if (triggerer.type == obj_t_npc):
			if ((triggerer.stat_level_get(stat_alignment) == LAWFUL_GOOD) or (triggerer.stat_level_get(stat_alignment) == NEUTRAL_GOOD) or (triggerer.stat_level_get(stat_alignment) == CHAOTIC_GOOD)):
				attachee.float_line(game.random_range(220,222),leader)
				return SKIP_DEFAULT
	return RUN_DEFAULT


def switch_to_ashrem( attachee, triggerer, line ):
	ashrem = find_npc_near(attachee,8040)
	if (ashrem != OBJ_HANDLE_NULL):
		triggerer.begin_dialog(ashrem,line)
		ashrem.turn_towards(attachee)
		attachee.turn_towards(ashrem)
	return SKIP_DEFAULT
